home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / java / slideshow / sources (skeleton) / imagebutton.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  4.0 KB  |  143 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.util.Hashtable;
  4.  
  5. /**
  6.  * An abstract class to implement the core features of a component with
  7.  * button like behavior, and the capability to display several images
  8.  * representing different states of the button.
  9.  */
  10. public abstract class ImageButton extends Component
  11. {
  12.     //Declare data members
  13.     //Insert "ImageButton data members"
  14.     
  15.     /**
  16.      * Constructs a default instance of this class.
  17.      */
  18.     public ImageButton()
  19.     {
  20.         //REGISTER_LISTENERS
  21.         //Insert "ImageButton register listeners"
  22.         
  23.         //Initialize state information
  24.         //Insert "ImageButton init state"
  25.     }
  26.  
  27.     /**
  28.      * Gets called when the mouse button is released on this button.
  29.      * @param isMouseInside, if true, the mouse is located inside the button area,
  30.      * if false the mouse is outside the button area.
  31.      */
  32.     protected void handleMouseRelease(boolean isMouseInside)
  33.     {
  34.         //Handle firing an ActionEvent to our listeners if the mouse was released
  35.         //inside the button.
  36.         //Insert "ImageButton handleMouseReleased"
  37.     }
  38.  
  39.     /**
  40.      * Gets called when the mouse crosses into or out of the button area.
  41.      * @param isMouseInside, is true if the mouse is in the button area,
  42.      * false if it is outside.
  43.      * @param isMouseDown, is true if the mouse button is pressed, false if it is not.
  44.      */
  45.     protected abstract void handleRollover(boolean isMouseInside, boolean isMouseDown);
  46.     
  47.     /**
  48.      * Gets called when the mouse button is pressed on this button.
  49.      */
  50.     protected abstract void handleMousePressed();
  51.  
  52.  
  53.     /**
  54.      * Adds an image to the button.
  55.      * @param imagePath, the location of the image resource to use.
  56.      * This path is relative to the location of this class file.
  57.      * @param imageName, the name used to identify the image for later
  58.      * use in this button.
  59.      * @see #removeImage
  60.      */
  61.     public void addImage(String imagePath, String imageName)
  62.     {
  63.         //Handle storing the information in our internal data structure.
  64.         //Insert "ImageButton addImage"
  65.     }
  66.     
  67.     /**
  68.      * Removes an image from the button
  69.      * @param imageName, the identifying name of the image to remove.
  70.      * @see #addImage
  71.      */
  72.     public void removeImage(String imageName)
  73.     {
  74.         //Handle removing the image from our internal data structure.
  75.         //Insert "ImageButton removeImage"
  76.     }
  77.     
  78.     /**
  79.      * Sets the image for the button to use as its current image.
  80.      * @param imageName, the identifying name of the image to use.
  81.      */
  82.     public void setImage(String imageName)
  83.     {
  84.         //Handle locating the image in our internal data structure,
  85.         //setting it as the current image, and repainting the button.
  86.         //Insert "ImageButton setImage"
  87.     }
  88.     
  89.     /**
  90.      * Gets the name of the image currently in use.
  91.      * @return The identifying name of the image being used.
  92.      */
  93.     public String getImage()
  94.     {
  95.         //Return the current image name.
  96.         //Insert "ImageButton getImage"
  97.     }
  98.     
  99.     /**
  100.      * Gets the actual Image Object which is currently being used.
  101.      * @return The java.awt.Image currently in use.
  102.      */
  103.     public Image getImageObject()
  104.     {
  105.         //Return the current image object.
  106.         //Insert "ImageButton getImageObject"
  107.     }
  108.  
  109.     
  110.     //Routines for handling ActionListener management.
  111.     //Insert "ImageButton Action Management"
  112.  
  113.     /** 
  114.      * Returns the preferred size of this component.
  115.      * @see #getMinimumSize
  116.      * @see LayoutManager
  117.      */
  118.     public Dimension getPreferredSize()
  119.     {
  120.         //If the current image is not null, then return the size of the image.
  121.         //If it is null, defer to the super class.
  122.         //Insert "ImageButton getPreferredSize"
  123.     }
  124.  
  125.     /** 
  126.      * Paints the component.  This method is called when the contents
  127.      * of the component should be painted in response to the component
  128.      * first being shown or damage needing repair.  The clip rectangle
  129.      * in the Graphics parameter will be set to the area which needs
  130.      * to be painted.
  131.      * @param g the specified Graphics window
  132.      * @see #update
  133.      */
  134.     public void paint(Graphics g)
  135.     {
  136.         //Let the super class draw, then handle drawing the current image.
  137.         //Insert "ImageButton paint"
  138.     }
  139.  
  140.     //Inner class for handing mouse events.
  141.     //Insert "ImageButton Mouse Handling"
  142. }
  143.